package cn.itcast.service.impl;

import cn.itcast.dao.StandardRepository;
import cn.itcast.domain.base.Standard;
import cn.itcast.service.StandardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class StandardServiceImpl  implements StandardService {
    @Autowired
    private StandardRepository standardRepository;
    @Override
    @Transactional
    @CacheEvict(value = "bos",allEntries = true)
    public void save(Standard standard) {
        standardRepository.save(standard);
    }

    @Override
    @Cacheable(value = "bos",key = "#pageable.pageNumber+'_'+#pageable.pageSize")
    public Page<Standard> findPageDate(Pageable pageable) {
        return standardRepository.findAll(pageable);
    }

    @Override
    @Cacheable("bos")
    public List<Standard> findAll() {
        return standardRepository.findAll();
    }
    /*
       缓存注解
        cacheable (value="缓存区名" key=对缓存区设置条件 ) 将查询结果存入缓存
        cacheevit (value="缓存区名",allentries =true/false) 数据变更时,将缓存区数据清空
     */
}
